r'''
构造 有道背单词 格式的单词本
Input: 词汇书名称（如CET6） 和 单词本名字（含后缀），如 word list1.txt
Output: 有道背单词格式的 单词本，与原单词本同名，生成在regularized lists文件夹下
Note: 单词本必须是txt格式，且放在original lists文件夹下的 <你的词汇书文件夹> 下
执行格式: python3 handle.py <book name> <list name>
        e.g. python3 handle.py CET6 word\ list1.txt 
        注意名字中有空格需要加转义符
                        R.G.
                    2021.03.17

'''

import os,sys

PROJECT_ROOT_DIR = os.getcwd()
PROCESSING_DIR = 'original lists'
PRODUCED_DIR = 'regularized lists'

def list_regularization(book_name, list_name):
    print('-'*10 + ' Processing '+ '-'*10)
    book_path = os.path.join(PROJECT_ROOT_DIR, PROCESSING_DIR, book_name)
    if not os.path.exists(book_path):
        print('vocabulary book does not exist!\nProcess aborted.')
        return 
    list_path = os.path.join(book_path, list_name)
    with open(list_path, 'r') as f:
        word_list = f.read()
    word_join = '#' + '# #'.join(word_list.split())+ '#'
    produced_book_path = os.path.join(PROJECT_ROOT_DIR, PRODUCED_DIR, book_name)
    if not os.path.exists(produced_book_path):
        os.mkdir(produced_book_path)
    produced_list_path = os.path.join(produced_book_path, list_name)
    with open(produced_list_path, 'w') as f:
        f.write(word_join)
    print('Process completed !')


if __name__ == "__main__":
    list_regularization(sys.argv[1], sys.argv[2])